//
//  LXSignContractApplyViewController.m
//  ZuLinProject
//
//  Created by bancheng on 2022/1/4.
//  Copyright © 2021 LX_App. All rights reserved.
//

#import "LXSignContractApplyViewController.h"
#import "LXTableViewCell.h"
#import "LXSignContractModel.h"
#import "LXChooseBtnTableViewCell.h"
#import "LXChooseCarViewViewController.h"
#import "LXChooseCustomViewController.h"
#import "KeHuInfoModel.h"
#import "FuZeRenModel.h"
#import "LXSignUpContractTableViewCell.h"
#import "LXBigImageView.h"
#import "LXSignBlockViewController.h"
#import <UMShare/UMShare.h>
#import <UShareUI/UShareUI.h>
#import "LXRemarkTabelViewCell.h"
#import "LXSignPayRentPlanTableViewCell.h"
#import "LXSignRentTableViewCell.h"
#import "LXPlanCollectionView.h"
@interface LXSignContractApplyViewController ()<UITableViewDelegate,UITableViewDataSource,LXDelImageViewDelegate>

@property (nonatomic) UITableView *tableView;
@property (nonatomic) NSMutableArray *data;
@property (nonatomic) NSMutableDictionary *loanDic;
@property (nonatomic) NSDictionary *selDic;
@property (nonatomic) NSArray *signTypeData; // 签约数据源
@property (nonatomic) NSInteger signType; // 签约类型，1：租车 2：购车，3:以租代购

@property (nonatomic) CheLiangModel *carModel; // 车辆数据
@property (nonatomic) FuZeRenModel *fuZeModel; //  负责人模型
@property (nonatomic) KeHuInfoModel *keHuModel;// 客户模型
@property (nonatomic) NSString *payDate;// 每月付款日

@property (nonatomic) NSMutableArray *contractData;
/**提交时使用*/
@property (nonatomic) NSMutableArray *subContractData;
@property (nonatomic) UIScrollView *scrollView;
// 是否上传了验车单
@property (nonatomic) BOOL isUpCheckImg;
// 是否上传了行驶证
@property (nonatomic) BOOL isUpDrivingImg;
// 是否上传了车辆照片
@property (nonatomic) BOOL isUpCarImg;
/**支付计划表*/
@property (nonatomic) NSMutableArray *payPlanAry;
// 总分期数
@property (nonatomic) CGFloat totalStages;
@end

@implementation LXSignContractApplyViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    if (self.type==1) {
        [self layoutCustomNav:self.view title:@"创建新签约"];
    }
    else if (self.type==2) {
        [self layoutCustomNav:self.view title:@"一键签约"];
    }
    
    else {
        [self layoutCustomNav:self.view title:@"一键续约"];
    }
    
    [self.view addSubview:self.tableView];
    
    [self.tableView registerClass:[LXTableViewCell class] forCellReuseIdentifier:NSStringFromClass([LXTableViewCell class])];
    [self.tableView registerClass:[LXChooseBtnTableViewCell class] forCellReuseIdentifier:NSStringFromClass([LXChooseBtnTableViewCell class])];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([LXSignUpContractTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([LXSignUpContractTableViewCell class])];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([LXRemarkTabelViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([LXRemarkTabelViewCell class])];
    [self.tableView registerClass:[LXSignPayRentPlanTableViewCell class] forCellReuseIdentifier:NSStringFromClass([LXSignPayRentPlanTableViewCell class])];
    [self.tableView registerClass:[LXSignRentTableViewCell class] forCellReuseIdentifier:NSStringFromClass([LXSignRentTableViewCell class])];

    
    

    [self loadData];
    
    if (self.type==1 || self.type==2) {
        [self setBottomView:@"确认签约"];
    }
    else  if (self.type==3){
        [self setBottomViewWithText:@"一键续约"];
    }
    

}

- (void)loadData{
    
    self.loanDic  = [NSMutableDictionary dictionary];
    self.contractData = [NSMutableArray array];
    self.subContractData = [NSMutableArray array];
    // 默认租车
    self.signType = 1;
  
    [self.loanDic setValue:[YLUserMgr getEnterpriseName] forKey:@"companyName"];
    
//    if (!ObjectIsEmpty(self.signContractModel)) {
//        // 车辆信息
//        [self.loanDic setValue:self.signContractModel.carNum forKey:@"carNum"];
//        [self.loanDic setValue:[NSString stringWithFormat:@"%@ %@",self.signContractModel.carBrand,self.signContractModel.carModel] forKey:@"carBrand"];
//        self.carModel = [CheLiangModel new];
//        self.carModel.ID = self.signContractModel.carId;
//        self.carModel.carNum = self.signContractModel.carNum;
//        self.carModel.carBrand = self.signContractModel.carBrand;
//        self.carModel.carMode = self.signContractModel.carModel;
//    }
    
   
    // 修改的时候需要带入数据
    if (self.type==2||self.type==3) {
        
        // 车辆信息
        if (self.type == 2) {
            self.signType = 1;
        }
        else {
            self.signType = self.signContractModel.signType;
        }
        
        
        self.carModel = [CheLiangModel new];
        self.carModel.ID = self.signContractModel.carId;
        self.carModel.carNum = self.signContractModel.carNum;
        self.carModel.carBrand = self.signContractModel.signCarBrand;
        self.carModel.carMode = self.signContractModel.signModel;
        [self.loanDic setValue:self.signContractModel.carNum forKey:@"carNum"];
        [self.loanDic setValue:[NSString stringWithFormat:@"%@ %@",self.carModel.carBrand,self.carModel.carMode] forKey:@"carBrand"];
        
        
        
        // 签约客户
        [self.loanDic setValue:[NSString stringWithFormat:@"%@ %@",self.signContractModel.driverName,self.signContractModel.driverPhone] forKey:@"customerName"];
        self.keHuModel = [KeHuInfoModel new];
        self.keHuModel.driverId = self.signContractModel.driverId;
        self.keHuModel.customerName = self.signContractModel.driverName;
        self.keHuModel.customerPhone = self.signContractModel.driverPhone;
       
        // 开始日期
        NSString *nextDate = [NSString getCustomDateFromDate:self.signContractModel.endTime withDay:1];
        [self.loanDic setValue:nextDate forKey:@"beginTime"];
        [self.loanDic setValue:self.signContractModel.depost forKey:@"depost"];
        [self.loanDic setValue:self.signContractModel.depost forKey:@"firstPay"];
        [self.loanDic setValue:self.signContractModel.rent forKey:@"rent"];
        self.payDate = self.signContractModel.payDate;
        [self.loanDic setValue:[NSString stringWithFormat:@"每月%@日",self.payDate] forKey:@"payDate"];
        [self.loanDic setValue:self.signContractModel.remark forKey:@"remarks"];

       
        
    }
    else {
        
        if (!ObjectIsEmpty(self.signContractModel)) {
            self.carModel = [CheLiangModel new];
            self.carModel.ID = self.signContractModel.carId;
            self.carModel.carNum = self.signContractModel.carNum;
            self.carModel.carBrand = self.signContractModel.signCarBrand;
            self.carModel.carMode = self.signContractModel.signModel;
            
            [self.loanDic setValue:self.signContractModel.carNum forKey:@"carNum"];
            [self.loanDic setValue:[NSString stringWithFormat:@"%@ %@",self.carModel.carBrand,self.carModel.carMode] forKey:@"carBrand"];
            
        }
        
    }
    
    NSArray *ary0 = @[
        @{
            @"title":@"签约类型",
            @"key":@"signType",
            @"height":@([LXChooseBtnTableViewCell height:self.signTypeData])
        },
    ];
    [self.data addObject:ary0];
    NSArray *ary1 = @[
        @{
            @"title":@"客户信息",
            @"key":@"customerName",
            @"placeHolder" : @"请选择客户",
            @"canEdit":@(NO),
            @"showAccess":self.type==1?@(YES):@(NO),
            @"maxLength":@(1000),
            @"sel":self.type==1?@"clickCustomerName":@"",
            @"height":@(kComHeight)
        },
    ];
    [self.data addObject:ary1];
    
    NSArray *ary2 = @[
        @{
            @"title":@"车牌号",
            @"key":@"carNum",
            @"placeHolder" : @"请选择车牌号",
            @"canEdit":@(NO),
            @"showAccess":self.type==3?@(NO):@(YES),
            @"maxLength":@(1000),
            @"sel":self.type==3?@"":@"clickCarNum",
            @"height":@(kComHeight)
        },
        @{
            @"title":@"品牌型号",
            @"key":@"carBrand",
            @"placeHolder" : @"请选择品牌型号",
            @"canEdit":@(NO),
            @"showAccess":self.type==1?@(YES):@(NO),
            @"maxLength":@(1000),
            @"sel":@"",
            @"height":@(kComHeight)
        },
        @{
            @"title":@"签约企业",
            @"key":@"companyName",
            @"placeHolder" : @"请选择",
            @"canEdit":@(NO),
            @"showAccess":@(NO),
            @"maxLength":@(1000),
            @"sel":@"",
            @"height":@(kComHeight)
        },
    ];
    [self.data addObject:ary2];
    
    
    NSArray *ary3 = @[
        @{
            @"title":@"签约时间",
            @"key":@"signDate",
            @"placeHolder" : @"请选择签约时间",
            @"canEdit":@(NO),
            @"showAccess":@(YES),
            @"maxLength":@(1000),
            @"sel":@"clickSignDate",
            @"height":@(kComHeight)
        },
        @{
            @"title":@"合约开始时间",
            @"key":@"beginTime",
            @"placeHolder" : @"请选择开始时间",
            @"canEdit":@(NO),
            @"showAccess":self.type==3?@(NO):@(YES),
            @"maxLength":@(1000),
            @"sel":self.type==3?@"":@"clickBeginTime",
            @"height":@(kComHeight)
        },
        @{
            @"title":@"合约结束时间",
            @"key":@"endTime",
            @"placeHolder" : @"请选择结束时间",
            @"canEdit":@(NO),
            @"showAccess":@(YES),
            @"maxLength":@(1000),
            @"sel":@"clickEndTime",
            @"height":@(kComHeight)
        },
    ];
    [self.data addObject:ary3];
    
    NSArray *ary4 = @[
        @{
            @"title": self.type==3?(self.signType!=1?@"首付金额(元)":@"押金金额(元)"): @"押金金额(元)",
            @"key":@"depost",
            @"placeHolder" : @"请输入押金金额",
            @"canEdit":self.type==3?@(NO):@(YES),
            @"showAccess":@(NO),
            @"inputType":@(NUM_DECIMAL),
            @"keyboardType":@(UIKeyboardTypeDecimalPad),
            @"maxLength":@(8),
            @"sel":@"",
            @"height":@(kComHeight)
        }.mutableCopy,
        @{
            @"title":self.type==3?(self.signType!=1?@"月供金额(元)":@"每期金额(元)"): @"每期金额(元)",
            @"key":@"rent",
            @"placeHolder" : @"请输入租金金额",
            @"canEdit":self.type==3?@(NO):@(YES),
            @"showAccess":@(NO),
            @"inputType":@(NUM_DECIMAL),
            @"keyboardType":@(UIKeyboardTypeDecimalPad),
            @"maxLength":@(8),
            @"sel":@"",
            @"height":@(kComHeight)
        }.mutableCopy,
        @{
//            @"title":self.type==3?(self.signType!=1?@"分期结算日期":@"交租日期"): @"交租日期",
            @"title":@"交租日期",
            @"key":@"payDate",
            @"placeHolder" : @"请选择",
            @"canEdit":@(NO),
            @"showAccess":self.type==3?@(NO):@(YES),
            @"maxLength":@(1000),
            @"sel":self.type==3?@"":@"clickPayDate",
            @"height":@(kComHeight)
        }.mutableCopy,
    ];
    [self.data addObject:ary4];
    

    NSArray *ary5 = @[
        @{
            @"title":@"上传合同",
            @"key":@"upContract",
            @"height":@(370)
        },
    ];
    [self.data addObject:ary5];
    
    NSArray *ary6 = @[
        @{
            @"title":@"备注",
            @"key":@"remarks",
            @"height":@(150)
        },

    ];
    [self.data addObject:ary6];
    
    
    NSArray *ary7 = @[
        @{
            @"title":@"租金支付计划表",
            @"key":@"planForm",
            @"height":@(300)
        },
    ];
    [self.data addObject:ary7];
    
   
    [self.tableView reloadData];
 
    

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.data.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.data[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = self.data[indexPath.section][indexPath.row];
    if ([dic[@"key"] isEqualToString:@"planForm"]) {
        return [LXSignPayRentPlanTableViewCell getHeight:self.payPlanAry];
    }
    return [dic[@"height"] doubleValue];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSDictionary *dic = self.data[indexPath.section][indexPath.row];
    
    // 租金计划表
    if([dic[@"key"]  isEqualToString:@"planForm"]){
    
        
        LXSignPayRentPlanTableViewCell *cell = [[LXSignPayRentPlanTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([LXSignPayRentPlanTableViewCell class]) WithData:!ObjectIsEmpty(self.payPlanAry)?self.payPlanAry:[NSMutableArray array] WithSignType:self.signType IsShow:NO];
       cell.selectionStyle = UITableViewCellSelectionStyleNone;
       [cell setClipsToBounds:YES];
       cell.titleLab.text = dic[@"title"];
        
        
        
        [cell setClickBtnAction:^(LXSignContractModel * _Nonnull model) {
                    
            
            [Tool showSheetTitle:nil msg:nil cancelTitle:@"取消" oneBtnTitle:@"新增" twoBtnTitle:@"修改" threeBtnTitle:@"删除" cancelHandlerBlock:^{
            } oneHandlerBlock:^{
                // 新增
                [self showPlanViewWithType:1 andWithModel:model];
            } twoHandlerBlock:^{
                // 修改
                [self showPlanViewWithType:2 andWithModel:model];
            } threeHandlerBlock:^{
                
                
                [Tool showAlertTitle:nil msg:@"您确定要删除该条计划吗?" cancelTitle:@"取消" commitBtnTitle:@"删除" cancelHandlerBlock:^{
                } commitHandlerBlock:^{
                    [self.payPlanAry removeObject:model];
                    // 总期数
                    self.totalStages = self.payPlanAry.count - 1;
                    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:self.data.count-1]  withRowAnimation:UITableViewRowAnimationNone];

                } onVC:self];
                
            } onVC:self];
            
            
        }];
        
       return cell;
   }
    
    
    
    
    // 备注
    if([dic[@"key"]  isEqualToString:@"remarks"]){
       LXRemarkTabelViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXRemarkTabelViewCell class])];
       cell.selectionStyle = UITableViewCellSelectionStyleNone;
       [cell setClipsToBounds:YES];
       cell.textView.placeholder = @"请输入 ~";
       cell.textView.maxLength = 200;
       cell.remarkTitle.text = dic[@"title"];
       cell.textView.text = self.loanDic[dic[@"key"]];
       [cell setTextViewEdit:^(NSString * _Nonnull textStr) {
           self.loanDic[dic[@"key"]]  = textStr;
       }];
       return cell;
   }
    
    
    
    if ([dic[@"key"] isEqualToString:@"upContract"]) {
        
        LXSignUpContractTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXSignUpContractTableViewCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setClipsToBounds:YES];
        cell.checkCarUrl = self.checkCarUrl;
        cell.contractData = self.contractData;
        cell.driverUrl = self.driverUrl;
        cell.carUrl = self.carUrl;
        cell.type = self.type;
        if (self.type == 3) {
            
            
            cell.checkTitleLb.textColor = Color333;
            if (!StringIsEmpty(self.checkCarUrl)) {
                cell.footDelBtn.hidden = YES;
                cell.checkTitleLb.text = @"验车单";
            }
            else {
                cell.checkTitleLb.text = @"*验车单";
                [cell.checkTitleLb addAttributes:TextAttrCorlor(UIColor.redColor) forString:@"*"];
            }
            
            if (!StringIsEmpty(self.driverUrl)){
                cell.driverDelBtn.hidden = YES;
                cell.driverTipsLab.hidden = NO;
            }
            if (!StringIsEmpty(self.carUrl)) {
                cell.carDelBtn.hidden = YES;
            }
        }
        
        [cell setContractAction:^(NSArray * _Nonnull contractData) {
            [self.contractData addObjectsFromArray:contractData];
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];

        }];
        [cell.headNumLab whenTapped:^{
               
            LXBigImageView *view = [[LXBigImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight) WithImageAry:self.contractData];
            view.tag = 123456;
            view.delegate = self;
            view.imgArys = self.contractData;
            [[UIApplication sharedApplication].delegate.window addSubview:view];
        
        }];
        
        
        [cell.footDelBtn whenTapped:^{
            self.checkCarUrl = @"";
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        }];
        [cell setClickAction:^(NSString * _Nonnull url, NSInteger type) {
            if (type == 1) {
                self.checkCarUrl = url;
                self.isUpCheckImg = YES;
            }
            else if(type == 2) {
                self.driverUrl = url;
                self.isUpDrivingImg = YES;
            }
            else if(type == 3) {
                self.carUrl = url;
                self.isUpCarImg = YES;
            }
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        }];
        
        [cell.driverDelBtn whenTapped:^{
            self.driverUrl = @"";
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        }];
        
        [cell.carDelBtn whenTapped:^{
            self.carUrl = @"";
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        }];
        

        return cell;
    }
    
    // 签约类型/付款方式
    else if ([dic[@"key"] isEqualToString:@"signType"]) {
        NSArray *tempAry = self.signTypeData;
       LXChooseBtnTableViewCell *cell = [[LXChooseBtnTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([LXChooseBtnTableViewCell class]) WithData:tempAry];

       cell.selectionStyle = UITableViewCellSelectionStyleNone;
       [cell setClipsToBounds:YES];
        if(self.type == 3) {
            cell.canEdit = NO;
        }
        else {
            cell.canEdit = YES;
        }
       
       cell.titleLab.text = dic[@"title"];
       [cell setClickBtnBlock:^(NSInteger Id) {
           
           
           if ([dic[@"key"] isEqualToString:@"signType"]) {
               self.signType = Id;
               
               [self.loanDic setValue:@"" forKey:@"depost"];
               [self.loanDic setValue:@"" forKey:@"rent"];
               [self.loanDic setValue:@"" forKey:@"firstPay"];
               [self.loanDic setValue:@"" forKey:@"beginTime"];
               [self.loanDic setValue:@"" forKey:@"endTime"];
               [self.loanDic setValue:@"" forKey:@"payDate"];
               self.payDate = @"";
               self.totalStages = 0;
               self.payPlanAry = nil;
               
               
               [self payPlanAction];
               [self.data enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
                   NSArray *arr = (NSArray*)obj;
                   
                   [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                       // 租车
                       if (Id==1) {
                           
                           NSMutableDictionary *dic = (NSMutableDictionary *)obj;
                           
                           // 押金
                           if ([dic[@"key"] isEqualToString:@"depost"]) {
                               [dic setValue:@"押金金额(元)" forKey:@"title"];
                               [dic setValue:@"请输入押金金额" forKey:@"placeHolder"];
                               [dic setValue:@(8) forKey:@"maxLength"];
                               [dic setValue:@(UIKeyboardTypeDecimalPad) forKey:@"keyboardType"];
                               [self.loanDic setValue:@"" forKey:@"depost"];
                               [self.tableView reloadData];
                               
                           }
                           // 租金
                           if ([dic[@"key"] isEqualToString:@"rent"]) {
                               [dic setValue:@"每期金额(元)" forKey:@"title"];
                               [dic setValue:@"请输入租金金额" forKey:@"placeHolder"];
                               [dic setValue:@(8) forKey:@"maxLength"];
                               [dic setValue:@(UIKeyboardTypeDecimalPad) forKey:@"keyboardType"];
                               [self.loanDic setValue:@"" forKey:@"rent"];
                               [self.tableView reloadData];
                               
                           }
//                           // 交租日期
//                           if ([dic[@"key"] isEqualToString:@"payDate"]) {
//                               [dic setValue:@"交租日期" forKey:@"title"];
//                               [self.tableView reloadData];
//                           }
                       }
                       // 购车
                       else if(Id==2 || Id==3)  {
                           NSMutableDictionary *dic = (NSMutableDictionary *)obj;
                        
                           if ([dic[@"key"] isEqualToString:@"depost"]) {
                               [dic setValue:@"首付金额(元)" forKey:@"title"];
                               [dic setValue:@"请输入首付金额" forKey:@"placeHolder"];
                               [dic setValue:@(5) forKey:@"maxLength"];
                               [dic setValue:@(UIKeyboardTypeDecimalPad) forKey:@"keyboardType"];
                               [self.loanDic setValue:@"" forKey:@"depost"];
                               [self.tableView reloadData];
                           }
                           
                           if ([dic[@"key"] isEqualToString:@"rent"]) {
                               [dic setValue:@"月供金额(元)" forKey:@"title"];
                               [dic setValue:@"请输入月供金额" forKey:@"placeHolder"];
                               [dic setValue:@(5) forKey:@"maxLength"];
                               [dic setValue:@(UIKeyboardTypeDecimalPad) forKey:@"keyboardType"];
                               [self.loanDic setValue:@"" forKey:@"rent"];
                               [self.tableView reloadData];
                           }
//                           // 分期结算日期
//                           if ([dic[@"key"] isEqualToString:@"payDate"]) {
//                               [dic setValue:@"分期结算日期" forKey:@"title"];
//                               [self.tableView reloadData];
//                           }
                       }
                    
                       
                   }];

                   
               }];
           }
           
       }];
       
       
       
       return cell;
    }
   
    
    if ([dic[@"key"] isEqualToString:@"rent"]) {
         LXSignRentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXSignRentTableViewCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.titleLab.text = dic[@"title"];
        cell.textFiled.text = self.loanDic[dic[@"key"]];
        
        if (self.type == 3) {
            cell.textFiled.userInteractionEnabled = NO;
        }
        else {
            cell.textFiled.userInteractionEnabled = YES;
        }
        
        cell.unit.text = [NSString stringWithFormat:@"(总共分%@期)",@(self.totalStages)];

        cell.textfiledChangeBlock = ^(NSString * _Nonnull textStr) {
            
            
            self.loanDic[dic[@"key"]]  = textStr;

            if ([dic[@"key"] isEqualToString:@"rent"]||
                [dic[@"key"] isEqualToString:@"depost"]) {
                [self payPlanAction];
            }
        };
        return cell;
    }
    
    
    __block LXTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([LXTableViewCell class])];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.cellDic = dic;
    cell.textFiled.hidden = NO;
    cell.subTitleLab.hidden = YES;
    cell.textFiled.text = self.loanDic[dic[@"key"]];
    
    if ([dic[@"key"] isEqualToString:@"companyName"] || ([dic[@"key"] isEqualToString:@"carBrand"] && !StringIsEmpty(self.loanDic[dic[@"key"]]))) {
        cell.textFiled.hidden = YES;
        cell.subTitleLab.hidden = NO;
        cell.subTitleLab.text = self.loanDic[dic[@"key"]];
    }
    
    
    
    
    LXTableViewCell *blockCell = cell;

    cell.textfiledChangeBlock = ^(NSString * _Nonnull textStr) {

        
        // 金额
        if ([dic[@"key"] isEqualToString:@"firstPay"] && self.signType != 1) {
            if ([textStr doubleValue] > 100) {
                textStr = @"100";
                blockCell.textFiled.text = textStr;
            }
        }
        self.loanDic[dic[@"key"]]  = textStr;
        
        if ([dic[@"key"] isEqualToString:@"depost"]||
            [dic[@"key"] isEqualToString:@"firstPay"]) {
            [self payPlanAction];
        }
      
        
    };
    
    
    return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *vv = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
    vv.backgroundColor = [UIColor colorWithHexString:@"#F7F8FA"];
    return vv;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSDictionary *dic = self.data[indexPath.section][indexPath.row];
    self.selDic = dic;
    NSString * selName = dic[@"sel"];
    SEL action = NSSelectorFromString(selName);
    if ([self respondsToSelector:action]) {
        [self performSelector:action withObject:nil afterDelay:0];
    }

}
-(void)showPlanViewWithType:(NSInteger)type andWithModel:(LXSignContractModel *)model{
    LXPlanCollectionView *vc = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([LXPlanCollectionView class]) owner:nil options:nil].firstObject;
    vc.type = type;
    vc.model = model;
    vc.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [self.view addSubview:vc];
    
    
    [vc setClickPlanAction:^(LXSignContractModel * _Nonnull mm) {

        // 新增
        if (type == 1) {
            NSInteger index = [self.payPlanAry indexOfObject:model];
            [self.payPlanAry insertObject:mm atIndex:index + 1];
            self.totalStages++;
            
        }
        [self.tableView reloadData];
//        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:self.data.count-1]  withRowAnimation:UITableViewRowAnimationNone];
        
    }];
  
    
    
}
#pragma mark -- 选择签订日期
-(void)clickSignDate{
    [self.view endEditing:YES];
    DatePickView *datePicker =[[DatePickView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) withDateStr:self.loanDic[@"signDate"] withIsMaxDate:YES withNoForward:NO WithTips:@"请选择签订日期"] ;
    [datePicker showBoomView];
    [[[UIApplication sharedApplication].delegate window] addSubview:datePicker];
    WEAKSELF
    datePicker.block = ^(NSString *yearString){
        [weakSelf.loanDic setObject:yearString forKey:weakSelf.selDic[@"key"]];
        [weakSelf.tableView reloadData];
    };
}
#pragma mark -- 选择合约开始日期
-(void)clickBeginTime{
    [self.view endEditing:YES];
    DatePickView *datePicker =[[DatePickView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) withDateStr:self.loanDic[@"beginTime"] withIsMaxDate:YES withNoForward:NO WithTips:@"请选择合约开始日期"] ;
    [datePicker showBoomView];
    [[[UIApplication sharedApplication].delegate window] addSubview:datePicker];
    WEAKSELF
    datePicker.block = ^(NSString *yearString){
        
        if([NSString compareDate:self.loanDic[@"endTime"] withDate:yearString withFormat:k_DateFormat]==1){
            showAlert(@"开始日期不能大于结束日期");
        }
        else {
            [weakSelf.loanDic setObject:yearString forKey:weakSelf.selDic[@"key"]];
            
            NSString *payDate =  [NSString stringWithFormat:@"每月%@日",@([[yearString substringFromIndex:yearString.length - 2] intValue])];
            [self.loanDic setValue:payDate forKey:@"payDate"];
            
            self.payDate = [yearString substringFromIndex:yearString.length - 2];

            
            if (!StringIsEmpty(self.loanDic[@"endTime"])) {
                // 总天数
                NSInteger totalDay = [NSString dateCompare:self.loanDic[@"endTime"] secondTime:self.loanDic[@"beginTime"]];
                // 总期数
                self.totalStages = ceilf(totalDay/30.0);
            }
            
            [weakSelf.tableView reloadData];
            
            [self payPlanAction];
            
            
            
        }

    };
}
#pragma mark -- 选择合约结束日期
-(void)clickEndTime{
    [self.view endEditing:YES];
    DatePickView *datePicker =[[DatePickView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) withDateStr:self.loanDic[@"endTime"] withIsMaxDate:YES withNoForward:NO WithTips:@"请选择合约结束日期"] ;
    [datePicker showBoomView];
    [[[UIApplication sharedApplication].delegate window] addSubview:datePicker];
    WEAKSELF
    datePicker.block = ^(NSString *yearString){
        if([NSString compareDate:yearString withDate:self.loanDic[@"beginTime"] withFormat:k_DateFormat]==1){
            showAlert(@"结束日期不能小于开始日期");
        }
        else {
            [weakSelf.loanDic setObject:yearString forKey:weakSelf.selDic[@"key"]];
        
            if (!StringIsEmpty(self.loanDic[@"endTime"])) {
                // 总天数
                NSInteger totalDay = [NSString dateCompare:self.loanDic[@"endTime"] secondTime:self.loanDic[@"beginTime"]];
                // 总期数
                self.totalStages = ceilf(totalDay/30.0);
            }
            
            [weakSelf.tableView reloadData];
            
            
            [self payPlanAction];
            
        }

    };
}
// MARK: 租金支付计划表
-(void)payPlanAction{
    
    
    if (StringIsEmpty(self.loanDic[@"depost"]) ||
        StringIsEmpty(self.loanDic[@"beginTime"])||
        StringIsEmpty(self.loanDic[@"endTime"])||
        StringIsEmpty(self.loanDic[@"rent"])||
        StringIsEmpty(self.payDate)) {
        
        
        
        return;
    }
    

    // 总天数
    NSInteger totalDay = [NSString dateCompare:self.loanDic[@"endTime"] secondTime:self.loanDic[@"beginTime"]];
    // 总期数
    CGFloat totalStages = ceilf(totalDay/30.0);
    /**款项类别 0租金 1租车押金 2购车首付,3购车月供,4购车尾款, 5平台返佣 6保险赔付*/
    NSInteger fundType = 1;
    if (self.signType == 1) {
        fundType = 1;
    }
    else {
        fundType = 2;
    }
    
    NSMutableArray *ary = @[
        @{
            @"fundType":@(fundType),
            @"exceptReceiveDate":self.loanDic[@"beginTime"],
            @"amount":self.loanDic[@"depost"],
            @"remark":self.signType==1?@"押金":@"首付",
            @"period":@"",
        },
    ].mutableCopy;
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    formatter.dateFormat = @"yyyy-MM-dd";
    NSString *nextYY = [self.loanDic[@"beginTime"] componentsSeparatedByString:@"-"][0];
    NSString *nextMM = [self.loanDic[@"beginTime"] componentsSeparatedByString:@"-"][1];
    NSDate *date = [formatter dateFromString:[NSString stringWithFormat:@"%@-%@-%02d",nextYY,nextMM,[self.payDate intValue]]];
    for (int i = 0; i<totalStages; i++) {

        if (self.signType == 1) {
            fundType = 0;
        }
        else {
            fundType = 3;
        }
        
        NSString *nowDate = [NSString getCustomDateFromDate:date withMonth:1 * i];
        
        NSDictionary *dic = @{
            @"fundType":@(fundType),
            @"exceptReceiveDate":nowDate,
            @"amount":self.loanDic[@"rent"],
            @"remark":[NSString stringWithFormat:@"第%d期%@",i+1,fundType==0?@"租金":@"月供"],
            @"period":@(i+1),
        };
        [ary addObject:dic];
    }


    self.payPlanAry = [LXSignContractModel mj_objectArrayWithKeyValuesArray:ary];
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:self.data.count-1]  withRowAnimation:UITableViewRowAnimationNone];
}



#pragma mark -- 选择付款日
-(void)clickPayDate{
    [self.view endEditing:YES];
    DatePickView *datePicker =[[DatePickView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) withDateStr:self.payDate withIsMaxDate:YES withNoForward:NO WithTips:@"请选择"] ;
    [datePicker showBoomView];
    [[[UIApplication sharedApplication].delegate window] addSubview:datePicker];
    WEAKSELF
    datePicker.block = ^(NSString *yearString){

        // 如果号数大于28号,就截止到28号
        if ([[yearString substringFromIndex:yearString.length-2] intValue]>28) {
            yearString  = @"28";
        }
        else {
            yearString = [NSString stringWithFormat:@"%@",@([[yearString substringFromIndex:yearString.length-2] intValue])];
        }
        
        self.payDate = yearString;
        [weakSelf.loanDic setObject:[NSString stringWithFormat:@"每月%@日",yearString] forKey:weakSelf.selDic[@"key"]];
        [weakSelf.tableView reloadData];
        
        
        [self payPlanAction];
        
        
    };
}


#pragma mark -- 选择车牌号
- (void)clickCarNum{
    
    LXChooseCarViewViewController *vc = [[LXChooseCarViewViewController alloc] init];
    vc.type = @"12";
    [vc setToSendValue:^(CheLiangModel * _Nonnull model) {
        self.carModel = model;
        [self.loanDic setValue:model.carNum forKey:self.selDic[@"key"]];
        [self.loanDic setValue:[NSString stringWithFormat:@"%@ %@",model.carBrand,model.carMode] forKey:@"carBrand"];

        [self.tableView reloadData];
        
    }];
    [self pushToNextController:vc];
}
#pragma mark -- 选择客户
-(void)clickCustomerName{
    LXChooseCustomViewController *vc = [[LXChooseCustomViewController alloc] init];
    [vc setToSendValue:^(KeHuInfoModel * _Nonnull model) {
        
        NSString *str = [model.customerPhone substringToIndex:3];
        str = [str stringByAppendingString:@"********"];
        [self.loanDic setValue: [NSString stringWithFormat:@"%@ %@",model.customerName,str]  forKey:@"customerName"];
        self.keHuModel = model;
        [self.tableView reloadData];
    }];
    [self pushToNextController:vc];
}

- (NSMutableArray *)data{
    if (!_data) {
        _data = [[NSMutableArray alloc]init];
    }
    return _data;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, kViewTopHeight, ScreenWidth, kScreenHeight - kViewTopHeight - 60) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor colorWithHexString:@"#F7F8FA"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.sectionFooterHeight = 10;
        _tableView.showsVerticalScrollIndicator = NO;
        if (@available(iOS 11.0, *)) {
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }
        
    }
    return _tableView;
}


#pragma mark -- 签约类型数据源
- (NSArray *)signTypeData{
    _signTypeData = @[
        @{
            @"title":@"租车",
            @"sel":@(NO),
            @"id":@(1)
        }.mutableCopy,
//        @{
//            @"title":@"购车",
//            @"sel":@(NO),
//            @"id":@(2)
//        }.mutableCopy,
        @{
            @"title":@"以租代购",
            @"sel":@(NO),
            @"id":@(3)
        }.mutableCopy,
    ];

    for (NSMutableDictionary *dic in _signTypeData) {
        if ([dic[@"id"] integerValue] == self.signType) {
            [dic setValue:@(YES) forKey:@"sel"];
            break;
        }
    }

    return _signTypeData;
}
// MARK: 续约
-(void)xuYueData{
    
    
    if (StringIsEmpty(self.loanDic[@"endTime"])) {
        showAlert(@"请选择合约结束日期");
        return;
    }
    if (ObjectIsEmpty(self.contractData)) {
        showAlert(@"请上传合同照片");
        return;
    }
    if (self.contractData.count < 2) {
        showAlert(@"合同照片不能少于两张");
        return;
    }
    
    [Tool showAlertTitle:@"是否确认提交" msg:nil cancelTitle:@"取消" commitBtnTitle:@"确定" cancelHandlerBlock:^{
    } commitHandlerBlock:^{
        
        NSMutableDictionary *dic = @{
            @"parentId":self.signContractModel.signContractId,//合约id
            @"endTime":self.loanDic[@"endTime"],//合约结束时间
            @"carNum":self.signContractModel.carNum,//车牌号
            @"carId":self.signContractModel.carId,
        }.mutableCopy;
            
        [self uploadContract:dic];
        
    } onVC:self];
    
}
#pragma mark ---- 确认新增/修改点击事件
- (void)clickBottomView:(UIButton *)sender{
    
    // 续约
//    if (self.type == 3) {
//        [self xuYueData];
//        return;
//    }
    
    
    if (StringIsEmpty(self.loanDic[@"customerName"])) {
        showAlert(@"请选择客户");
        return;
    }
   
    if (StringIsEmpty(self.loanDic[@"carNum"])) {
        showAlert(@"请选择车牌号");
        return;
    }
    if (StringIsEmpty(self.loanDic[@"carNum"])) {
        showAlert(@"请选择车牌号");
        return;
    }
    if (StringIsEmpty(self.loanDic[@"carBrand"])) {
        showAlert(@"请选择品牌型号");
        return;
    }
    if (StringIsEmpty(self.loanDic[@"signDate"])) {
        showAlert(@"请选择签约日期");
        return;
    }
    if (StringIsEmpty(self.loanDic[@"beginTime"])) {
        showAlert(@"请选择合约开始日期");
        return;
    }
    if (StringIsEmpty(self.loanDic[@"endTime"])) {
        showAlert(@"请选择合约结束日期");
        return;
    }
    if (StringIsEmpty(self.loanDic[@"payDate"])) {
        showAlert(@"请选择付款日");
        return;
    }
   
    if (StringIsEmpty(self.loanDic[@"depost"])) {
        // 租车
        if (self.signType == 1) {
            showAlert(@"请输入押金金额");
        }
        else{
            showAlert(@"请输入首付金额");
        }
        return;
    }
    
    if (StringIsEmpty(self.loanDic[@"rent"])) {
        if (self.signType == 1) {
            showAlert(@"请输入租金金额");
        }
        else{
            showAlert(@"请输入月供金额");
        }
        return;
    }
    
    
    
    
    
    if (StringIsEmpty(self.loanDic[@"payDate"])) {
        // 租车
//        if (self.signType == 1) {
            showAlert(@"请选择交租日期");
//        }
//        else{
//            showAlert(@"请选择分期结算日期");
//        }
        return;
    }
    
 
       
    if (ObjectIsEmpty(self.contractData)) {
        showAlert(@"请上传合同照片");
        return;
    }
    if (self.contractData.count < 2) {
        showAlert(@"合同照片不能少于两张");
        return;
    }
    if (StringIsEmpty(self.checkCarUrl)) {
        showAlert(@"请上传验车单");
        return;
    }
    
    [Tool showAlertTitle:@"是否确认提交" msg:nil cancelTitle:@"取消" commitBtnTitle:@"确定" cancelHandlerBlock:^{
    } commitHandlerBlock:^{
        
        
        NSMutableArray *intoFLows = [NSMutableArray array];
        
        for (LXSignContractModel *mm in self.payPlanAry) {
            NSDictionary *dic = @{
                @"fundType":@(mm.fundType),
                @"amount":mm.amount,
                @"exceptReceiveDate":mm.exceptReceiveDate,
                @"remark":mm.remark,
                @"period":@(mm.period)
            };
            [intoFLows addObject:dic];
        }
        
        
        
        NSMutableDictionary *dic = @{
            @"signType":@(self.signType),// 签约类型
            @"driverId":self.keHuModel.driverId,// 客户ID
            @"driverPhone":self.keHuModel.customerPhone,// 客户电话
            @"driverName":self.keHuModel.customerName,//  客户姓名
            @"carId":self.carModel.ID, // 车辆id
            @"carNum":self.carModel.carNum,//车牌号
            @"carBrand":self.carModel.carBrand,// 车辆品牌
            @"carModel":self.carModel.carMode,// 车型
            @"companyName":[YLUserMgr getEnterpriseName],// 签约企业名称
            @"companyId":[YLUserMgr getenterpriseID],// 签约企业名称
            @"signDate":self.loanDic[@"signDate"],// 签约日期
            @"beginTime":self.loanDic[@"beginTime"],// 开始日期
            @"endTime":self.loanDic[@"endTime"],// 结束日期
            @"rent":self.loanDic[@"rent"],// 租金金额
            @"depost":self.loanDic[@"depost"],// 押金金额
            @"firstPay":self.loanDic[@"depost"],// 首付
            @"signPeriods":@(self.totalStages),// 签约期数
            @"payDate":self.payDate,// 付款日/分期结算日期
            @"fromType":@(1), //  1 表示企业
            @"remark":self.loanDic[@"remarks"], //  备注
            @"appointmentId":self.signContractModel.appointmentId,// 预约id
            @"bookingId":self.signContractModel.bookingId,// 下定id
            @"intoFLows":intoFLows,// 收款项计划表
            @"parentId":self.signContractModel.signContractId,//合约id
            @"platformBrokerage":self.loanDic[@"platformBrokerage"], // 佣金

        }.mutableCopy;
        
        
        if (self.type == 2) {
            [dic setValue:self.signContractModel.businessName forKey:@"businessName"];
        }
        
        
        [self uploadContract:dic];
        
    } onVC:self];
    
    
}
// MARK: 上传合同照片
- (void)uploadContract:(NSMutableDictionary *)dic{
    dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    
    MBProgressHUD *hud = [MBProgressHUD showGif];
    
    dispatch_async(queue, ^{
        
        [self.contractData enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
            [MSNetworkManager postRevertUrl:POST_UploadFile_URL params:@{@"type":@"1"} formData:@[obj] success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
                if (isSuccess) {
                    [self.subContractData addObject:@{
                        
                        @"path":resonseObj[@"url"],
                        @"sort":@(idx),
                        @"type":@(1), // type==1 合同
                        
                    }];
                    if (idx == self.contractData.count - 1) {
                        [hud hide];
                        
                        [self subSignUrl:dic];
                        
                    }
                    dispatch_semaphore_signal(semaphore);
                }
            } failure:^(NSUInteger code, NSString * _Nonnull message) {
                dispatch_semaphore_signal(semaphore);
                [hud hide];
            } withShowHud:NO];
            
          
            dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
            
        }];
        
    });

}
// MARK: 提交签约
-(void)subSignUrl:(NSMutableDictionary *)dic{
    NSString *url;
    
    
    NSMutableArray *imgs = [NSMutableArray array];
    
    // 新增签约
    if (self.type==1 || self.type==2) {
        url = SigncontractAdd_URL;
    }
    // 修改签约的时候需要穿id
    else if (self.type==3) {
        url = [NSString stringWithFormat:@"%@",SigncontractRenew_URL];
    }
    
    // 合同照片
    [imgs addObjectsFromArray:self.subContractData];
    
    /**1:合同 | 2:验收  3:车辆  4:驾驶证  5：行驶证   6：车辆照片*/
    if(!StringIsEmpty(self.checkCarUrl))
    {
        [imgs addObject: @{
                @"path":self.checkCarUrl,
                @"sort":@(0),
                @"type":@(2),
        }];
    }
   
    
    //isUpDrivingImg == YES 表示上传过照片
    if (!StringIsEmpty(self.driverUrl)) {
        [imgs addObject: @{
            @"path":self.driverUrl,
            @"sort":@(0),
            @"type":@(5),
        }];
    }
    if (!StringIsEmpty(self.carUrl)) {
        [imgs addObject: @{
            @"path":self.carUrl,
            @"sort":@(0),
            @"type":@(3),
        }];
    }
    [dic setObject:[NSString toJSONData:imgs] forKey:@"imgs"];
    
    [MSNetworkManager postRevertUrl:url params:dic success:^(id  _Nonnull paginationObj, id  _Nonnull resonseObj, BOOL isSuccess, NSString * _Nonnull message) {
        if (isSuccess) {
            
            kUserDefaultSetBool(YES, kRefreshStr);
            
            if (self.type==1) {
                showAlert(@"新增签约成功");
            }
            else  if (self.type==2) {
                showAlert(@"一键签约成功");
            }
            else if (self.type==3) {
              
                LXSignBlockViewController *vc = [[LXSignBlockViewController alloc] init];
                vc.time = self.loanDic[@"endTime"];// 结束日期
                vc.type = 3;
                vc.fromVC = @"LXSignRecordViewController";
                [self pushToNextController:vc];
                return;
            }
    
           
            if (!StringIsEmpty(self.fromVC)) {
                [self backToVC:self.fromVC];
                return;
            }
            [self.navigationController popViewControllerAnimated:YES];
        }
       
    } failure:^(NSUInteger code, NSString * _Nonnull message) {
    } withShowHud:YES];

}
// MARK: 删除大图刷新table
- (void)reloadDataWithTableView{
    [self.tableView reloadData];
    
    LXBigImageView *view = [[UIApplication sharedApplication].delegate.window viewWithTag:123456];
    
    view.imgArys = self.contractData;
    
}
-(void)clickShareAction{
    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_QQ)]];
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        [self shareMiniProgramToPlatformType:platformType];
    }];
}
-(void)shareMiniProgramToPlatformType:(UMSocialPlatformType)platformType
{
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"邀请注册" descr:@"注注册利行司机版，签约赠送大量福利！" thumImage:[UIImage imageNamed:@"logo"]];
    //设置分享地址
    NSString *url = @"https://activity.lixingpt.com/invite2/#/about";
    shareObject.webpageUrl = url;
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data,NSError*error){
        if(error){
            NSLog(@"************Share fail with error %@*********",error);
        }else{
            NSLog(@"response data is %@",data);
        }
    }];
}
-(void)setBottomView:(NSString *)text{
    
    
    UIButton *shareBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, kScreenHeight - kComHeight + 15, 22, 22)];
    [shareBtn setImage:Image(@"sign分享") forState:UIControlStateNormal];
    [shareBtn whenTapped:^{
        [self clickShareAction];
    }];
    [self.view addSubview:shareBtn];
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(shareBtn.X_width + 15, kScreenHeight - kComHeight - 5, ScreenWidth - shareBtn.X_width - 35, kComHeight)];
    btn.backgroundColor = mainColor;
    [btn addCorner:4];
    [btn setTitle:text forState:UIControlStateNormal];
    [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    btn.titleLabel.font = Fond16;
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(clickBottomView:) forControlEvents:UIControlEventTouchUpInside];
    
    
}
@end
